package com.wxw.gulidemo.service.impl;

import com.wxw.gulidemo.client.ServiceEduClient;
import com.wxw.gulidemo.client.ServiceUcenterClient;
import com.wxw.gulidemo.entity.Order;
import com.wxw.gulidemo.mapper.OrderMapper;
import com.wxw.gulidemo.service.IOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wxw.gulidemo.utils.OrderNoUtils;
import com.wxw.gulidemo.vo.EduCourseVo;
import com.wxw.gulidemo.vo.UcenterMemberVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author xinxinzi
 * @since 2022-06-20
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Autowired
    private ServiceEduClient serviceEduClient;

    @Autowired
    private ServiceUcenterClient serviceUcenterClient;


    @Override
    public String createOrders(String courseId, String memberId) {
        EduCourseVo courseInfo = serviceEduClient.getCourseInfoByIdOrder(courseId);
        UcenterMemberVo memberInfo = serviceUcenterClient.getMemberInfoById(memberId);

        Order order = new Order();
        order.setMobile(memberInfo.getMobile());
        order.setNickname(memberInfo.getNickname());
        order.setMemberId(memberId);
        order.setCourseCover(courseInfo.getCover());
        order.setCourseId(courseId);
        order.setCourseTitle(courseInfo.getTitle());
        order.setTeacherName(courseInfo.getTeacherName());
        order.setTotalFee(courseInfo.getPrice());
        order.setStatus(0);//支付状态：（ 0：已支付，1：未支付 ）
        order.setPayType(1);//支付类型： 1：微信 ， 2：支付宝
        order.setOrderNo(OrderNoUtils.getOrderNo()); //订单号

        //保存订单
        baseMapper.insert(order);

        return order.getOrderNo();
    }
}
